package it.eng.area118.mdocommon.android.util;

import java.io.IOException;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

public class JsonConverter {

	ObjectMapper mapper = new ObjectMapper();

	public <E> E convert(Class<E> clazz, String json) {
		try {
			return this.mapper.readValue(json, clazz);
		} catch (JsonParseException e) {
			// XXX Auto-generated catch block
			e.printStackTrace();
		} catch (JsonMappingException e) {
			// XXX Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// XXX Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	public <E> String convert(E object) {
		try {
			return this.mapper.writeValueAsString(object);
		} catch (JsonGenerationException e) {
			// XXX Auto-generated catch block
			e.printStackTrace();
		} catch (JsonMappingException e) {
			// XXX Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// XXX Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
}
